<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="用户名">
    <el-input v-model="form.userName" />
  </el-form-item>
  <el-form-item label="密码">
    <el-input v-model="form.userPass" style="" />
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">登录</el-button>
    <el-button>重置</el-button>
  </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { useCounterStore } from '@/stores/counter'
const store=useCounterStore()
const router=useRouter()
// do not use same name with ref
const form=reactive({
  userName:'',
  userPass:''
})

const onSubmit = () => {
  console.log('submit!')
  axios.get('https://localhost:7229/api/User/UserLogin',{
      params:{
          userName:form.userName,
          userPass:form.userPass
      }
  })
  .then(res=>{
      if(res.data.statusCode==0){
        console.log(res);
          ElMessage.success(res.data.message);
          store.current.userId=res.data.data[0].userId;
          store.current.userName=res.data.data[0].userName;
          store.current.userNickname=res.data.data[0].userNickname;
          store.current.roleId=res.data.data[0].roleId;
          store.current.roleName=res.data.data[0].roleName;
          router.push({
              name:"Main"
          })
      }
      else{
          ElMessage.error(res.data.message);
      }
  })
}
</script>





